<?PHP
	include "restritoCliente.php";
	header("Content-Type: text/html; charset=UTF-8", true);
?>

<!DOCTYPE html>
<html>
	<head>
		<title>Editar Pedido</title>
		<link rel="stylesheet" type="text/css"  href="css/style.css">
	</head>

	<body>
		<div class="container">
			<div class="head">
				<a id="logo" href="index.php">CKJ Store</a>
				
				<?php include 'head_login.php'; ?>
			</div>
			
			<!-- fim do header-->

			<?php include 'head_search.php'; 
			
			include_once 'BudgetControl.php';
			include_once 'Budget.php';
			
			if (!isset($_SESSION)){
				session_start();
			}
			$budget = BudgetControl::getDetailsBudget($_GET['id']);
			
	echo '<form class="join-form" name="detalhesPedido"  enctype="multipart/form-data" method="POST" action="">
		<span class="highlights">Orçamento Nº <strong>';
		echo $budget->BudgetId;
		
		echo '</strong></span>
        <div id="status">
          <h3>Status:</h3>
          <h4 >';
          echo $budget->Status;
          
          echo '</h4></div>
			<table class="table_pedido">
			<tr class="row" id="table-categories">';
          	if(strcmp('solicitado', $budget->Status) != 0)
			echo '<th class="categories">Incluir</th>';
				echo
				'<th class="categories">Descrição</th>
				<th class="categories">Foto</th>
				<th class="categories">Quant</th>
				<th class="categories">Preço Unitário</th>';
				
				$total = 0;
				foreach($budget->Products as $product)
				{
					echo '<tr class="row">';
					if(strcmp('solicitado', $budget->Status) != 0)
            			echo '<td class="table-column include"><input type="checkbox" ></td>';
					echo '<td class="table-column description"><span class="product-name">';
					echo $product->Nome;
					echo '</span><span class="product-categories">';
					echo implode(', ', $product->Categoria);
					echo '</span></td>
						<td class="table-column column-photo"><img class="photo" src="';
						
					
					if($product->Fotos[0] != null){
						$file = "imagensBanco/photo".$product->Id."". $product->Fotos[0][1];
						if(file_exists($file)) @unlink($file);
						$fp = fopen($file, "a");
						$escreve = fwrite($fp, $product->Fotos[0][0]);
					
						// Fecha o arquivo
						fclose($fp);
					}
					else
						$file = "imagensBanco/imagemIndisponivel.bmp";
						
						echo $file;
						
						
					echo '"/></td>
						<td class="table-column amount">';
						if(strcmp('solicitado', $budget->Status) != 0){
							echo '<input type="number" value="';
							echo $product->Quantidade;
							echo '">';
						}
						else{
							echo $product->Quantidade;
						}
						echo '</td>
						<td class="table-column single-price">';
						echo $product->UltimoPreco;
						echo '</td>
		 		 	      </tr>';
					$total = $total + ($product->UltimoPreco * $product->Quantidade); 
				}
				
	echo ' </table>	<div id="total"><h3>Total</h3> <p><strong>R$ ' .$total.'</strong></p> </div> </form>';
	if(strcmp('solicitado', $budget->Status) != 0)
echo			
			'<div class="content">
			<form id="form-confirmar-pedido" enctype="multipart/form-data"action="acaoCriarPedido.php" method="post">
            
           		<div id="comprovante" >
           		<input type="file" name="comprovante" value="Enviar comprovante"></div>
		   		
				<input class="submit" type="submit" value="Confirmar Pedido">
			</form>
			</div>';
			
			$_SESSION["idOrcamentoAtual"] = $budget->BudgetId;
			?>			
			
		</div>
	</body>
</html>